#-*- coding:utf-8 -*-
import os
import imp
import sys
import time
import json
import logging
import traceback
import urllib
import urllib2
import httplib
import gevent
import gevent.monkey
gevent.monkey.patch_socket()
from gevent.queue import Queue

from common import core

reload(sys)
sys.setdefaultencoding('utf8')
FastpyAutoUpdate = True





class dbsample():
    def __init__(self):
        # init here
        self.mysqlPool = core.MysqlPool(pool_size=2,host='127.0.0.1',port=3306,user='root',passwd='myroot123',db='woxiu_qyg_goods',charset='utf8')
        pass

    def test_mysql_pool(self, request, response_head):
        print 111
        conn = self.mysqlPool.get()
        print 222
        sql = "select goods_name from goods order by goods_id limit 1"
        try:
            conn.execute(sql)
            rows = conn.fetchall()
            print 333
        except Exception,e:
            print str(e)

        self.mysqlPool.put(conn)
        print 444
        #res = json.dumps(str(rows), ensure_ascii=True).encode('utf-8')
        #res = json.dumps(rows)
        #print rows

        return rows[0]["goods_name"].encode('utf-8')

